<?
ob_start('ob_gzhandler');
//mb_internal_encoding("UTF-8");
//ini_set("precision",28);
$runtime = microtime(true);
function errorHandler($errno, $errstr, $errfile, $errline) {
	$errname = "";
	switch ($errno) {
		case E_NOTICE:
			$errname="E_NOTICE";
			break;
		case E_WARNING:
			$errname="E_WARNING";
			break;
		case E_PARSE:
			$errname="E_PARSE";
			break;
		case E_NOTICE:
			$errname="E_NOTICE";
			break;
		case E_CORE_ERROR:
			$errname="E_CORE_ERROR";
			break;
		case E_CORE_WARNING:
			$errname="E_CORE_WARNING";
			break;
		case E_COMPILE_ERROR:
			$errname="E_COMPILE_ERROR";
			break;
		case E_COMPILE_WARNING:
			$errname="E_COMPILE_WARNING";
			break;
		case E_USER_ERROR:
			$errname="E_USER_ERROR";
			break;
		case E_USER_WARNING:
			$errname="E_USER_WARNING";
			break;
		case E_USER_NOTICE:
			$errname="E_USER_NOTICE";
			break;
		case E_STRICT:
			$errname="E_STRICT";
			break;
		case E_RECOVERABLE_ERROR:
			$errname="E_RECOVERABLE_ERROR";
			break;
		case E_DEPRECATED:
			$errname="E_DEPRECATED";
			break;
		case E_USER_DEPRECATED:
			$errname="E_USER_DEPRECATED";
			break;
		case E_ALL:
			$errname="E_ALL";
			break;
	}

	switch ($errno) {
		case E_NOTICE:
		case E_STRICT:
			break;
		default:
			throw new Exception(implode('', array('[', $errname, '] ', $errstr)), $errno);
			break;
	}

	/* Don't execute PHP internal error handler */
	return true;
}
//set_error_handler('errorHandler');

//ini_set('error_reporting', E_ALL);
//ini_set('log_errors', true);
//ini_set('track_errors', true);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
//error_reporting(E_ALL);
set_time_limit(0);
set_include_path( implode('',
array(
		'WEB-INF/src/', PATH_SEPARATOR, 
		'WEB-INF/classes/', PATH_SEPARATOR, 
		'WEB-INF/lib/', PATH_SEPARATOR, 
//get_include_path()
)
));
function import($str){
	$fileJsml = implode('', array ( str_replace('_', '/', $str), '.jsml' ) );
	$filePhp = implode('', array ( str_replace('_', '/', $str), '.php' ) );
	if(file_exists("WEB-INF/src/".$fileJsml) && !file_exists("WEB-INF/src/".$filePhp)){
		require_once $fileJsml;
		return;
	}
	require_once $filePhp;
}
function print_p($var,$return=false){
	if($return == true){
		$str = "<pre>".print_r($var,true)."</pre>";
		return $str;
	}
	echo "<pre>";
	print_r($var);
	echo "</pre>";
}

function prt($var){
	echo "<pre>";
	print_r($var);
	echo "</pre>";
}

function str($var){
	if($var===TRUE) return 'true';
	if($var===FALSE) return 'false';
	return $var;
}

function phpPath($str){
	return str_replace('.', '_', $str);
}

function returnMap($array){
	if(count($array)==0) return new stdClass();
	return $array;
}

function rmdirAll($dir){
	if( !file_exists($dir) ) return;
	foreach( scandir($dir) as $i => $value){
		if($value=="." || $value=="..") continue;
		$subDir = implode("/", array($dir, $value) );
		if(is_file($subDir)) unlink($subDir);
		else if(is_dir($subDir)) rmdirAll($subDir);
	}
	rmdir($dir);
}
require_once 'Jsml.jsml';
Jsml::main();
//fb(microtime(true) - $runtime);
?>